package ma.ensao.evalmetrics.controller.metrics;
//
//import java.io.BufferedReader;
//import java.io.File;
//import java.io.FileInputStream;
//import java.io.IOException;
//import java.io.InputStream;
//import java.io.InputStreamReader;
//
//import ma.ensao.evalmetrics.model.Admin;
//import ma.ensao.evalmetrics.model.LOC;
//
//public class LOCManager {
//	private LOC loc=new LOC();
//	int line=0;
//public  LOCManager() {
//		
//	}
//public LOC read(File file) throws IOException {
//		System.out.println("loc");
//		InputStream ips = new FileInputStream(file);
//		InputStreamReader ipsr = new InputStreamReader(ips);
//		BufferedReader br = new BufferedReader(ipsr);
//		String ligne;
//		 int line=0;
//		while ((ligne = br.readLine()) != null) {
//			ligne.trim();
//			
//			//jugement sur le ; pour LOC ???????
//			if(ligne.contains(";")==true){
//				line++;
//			}	
//		}
//		System.out.println("locbre de ligne de code est:"+""+line);
//		
//		br.close();
//		loc.setLine(line);
//		return loc;
//	}
//
//}
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import ma.ensao.evalmetrics.model.LOC;

/*
* M�triques de taille de l'objet logiciel
* Calcule LOC : mesure du  nombre de  lignes  de code
*/


public class LOCManager{
	private LOC loc =new LOC();
	String ligne;
	int allLine = 0;
	int commentline = 0;
	public LOCManager() {
		
	}
	public LOC read(File file){
		loc.setLine(0);
		allLine = 0;
		commentline = 0;
		InputStream ips = null;
		System.out.println(" Loc for file :"+file.getPath());
		try {
			ips = new FileInputStream(file);
		} catch (FileNotFoundException e1) {
			e1.printStackTrace();
		}
		InputStreamReader ipsr = new InputStreamReader(ips);
		BufferedReader br = new BufferedReader(ipsr);
		try {
			
			while ((ligne = br.readLine()) != null) {
				
				if(!ligne.isEmpty() ){ 
					if(!(ligne.contains("//")) && !(ligne.contains("/*"))){
					allLine++;
					}
			
				ligne.trim();
				
				if(ligne.contains("//")){
					
					commentline ++;
					}
				if(ligne.contains("/*")){
					if(ligne.contains("*/")){
						commentline ++;
						
					}
					else{
					commentline ++;
						
					BufferedReader r = br;
					while(!r.readLine().contains("*/")){
						commentline ++;
					}
					commentline ++;
					}
				}
				}		
			}
			br.close();
			ipsr.close();
			ips.close();
			
		} catch (IOException e) {
			e.printStackTrace();
		}
		loc.setLine(allLine);
		return loc;
	}
	public static void main(String[] args) throws IOException, ClassNotFoundException {
		//test a = new test("C:/Users/Hosni/Documents/test/AdminManager.java");

		File f=new File("C:/Users/sam/workspace/testem/src/hoho/Classtali.java");
		LOCManager a=new LOCManager();
		System.out.println(a.read(f).getLine());

		 
	}
}